#include "board.h"
#include "debug.h"
#include "voice_module.h"
#include "console_timer.h"
#include "FreeRTOS.h"
#include "task.h"

// 任务句柄
TaskHandle_t voice_task_handle;
TaskHandle_t shell_task_handle;
TaskHandle_t dht11_task_handle;
TaskHandle_t oled_task_handle;
TaskHandle_t key_task_handle;
TaskHandle_t adc_task_handle;
TaskHandle_t wfi_task_handle;
TaskHandle_t warning_task_handle;

// 底层板级初始化
void board_lowlever_init(void)
{
    SCB->VTOR = 0x08010000;     // 偏移中断向量表

    #if DEBUG       // 如果DEBUG宏开关打开，则初始化调试串口
        debug_init(115200);         // 初始化USART1
    #endif
    
    timer_init(100-1,84-1);     // 初始化定时器
    led_init();    // 初始化led1

    taskENTER_CRITICAL();
    xTaskCreate(wfi_task, "wfi_task", 512, NULL, 5, &wfi_task_handle);
    xTaskCreate(adc_task, "adc_task", 256, NULL, 3, &adc_task_handle);
    xTaskCreate(key_task, "key_task", 256, NULL, 3, &key_task_handle);
    xTaskCreate(shell_task, "shell_task", 1024, NULL, 3, &shell_task_handle);
    xTaskCreate(dht11_task, "dht11_task", 256, NULL, 2, &dht11_task_handle);
    xTaskCreate(oled_task, "oled_task", 1024, NULL, 2, &oled_task_handle);
    xTaskCreate(voice_task, "voice_task", 1024, NULL, 4, &voice_task_handle);
    xTaskCreate(warning_task, "warning_task", 256, NULL, 5, &warning_task_handle);
    vTaskSuspend(warning_task_handle); // 首次进入系统默认停止模式，挂起监测任务
    taskEXIT_CRITICAL();

    vTaskStartScheduler();
}

